<%--
  Created by IntelliJ IDEA.
  User: jiangzhenzhen
  Date: 2018/8/21
  Time: 16:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<html>
<head>
    <title>租赁管理</title>
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap.min.css" type="text/css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/lib/dataTables.bootstrap.css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/base/base.css" type="text/css">
    <link rel="stylesheet" href="${assets}/css/views/department/departmentMgr.css">
    <script src="${newframe}/js/compatible.js"></script>
    <%@ include file="/WEB-INF/jsp/component/commonBottom.jsp" %>
    <style>
        #mytool {
            float: right
        }

        @page {
            size: auto;   /* auto is the initial value */
            margin: 18mm 5mm 10mm 5mm;  /* this affects the margin in the printer settings 最关键的还是这个*/
        }

        @page body

        div:nth-child(1) {
            padding: 50px 0;
        }

        body {
            margin: 0mm; /* this affects the margin on the content before sending to printer */
            font-family: MicrosoftYaHei;
        }

        ul li {
            line-height: 200%;
        }
    </style>
    <script>
        // 请求数据渲染函数
        function GetData(id) {
            $.ajax({
                url: '${URL_RENT_PRINTINFO}',
                data: {
                    id: id
                },
                dataType: 'json',
                type: 'post',
                async: false,
                success: function (data) {
                    var Infor = data.data
                    $('.hospitalName').text(Infor.hospitalName)
                    $('.rentMan').text(Infor.rentMan)
                    $('.Card').text(Infor.idCard)
                }
            })
        }
    </script>
</head>
<body>
<div class="wrap">
    <div class="otherContent">
        <%@ include file="../breadline.jsp" %>
        <div class="content">
            <h1>租赁管理</h1>
            <div class="form">
                <label>设备名称:</label>
                <select id="instrumentType" name="instrumentType" class="SN">
                    <medi:configOpt name="instrumentName" />
                </select>
                <label>设备SN:</label>
                <input id="instrumentSN" name="instrumentSN" type="text" class="SN" placeholder="设备SN">
                <label>租借人:</label>
                <input id="rentMan" type="text" class="SN" placeholder="租借人" style="width: 7%">
                <label>身份证号:</label>
                <input id="idCard" type="text" class="SN" placeholder="身份证号">
                <label>租借状态:</label>
                <select id="rentStatus" name="rentStatus" class="SN" style="width: 7%">
                    <medi:configOpt name="rentStatus" />
                </select>
                <button class="search" id="query" onclick="refreshTable();">搜索</button>
            </div>
            <div id="tablepart">
                <table id="example" class="display" cellspacing="10" width="100%">
                    <thead>
                    <tr style="background:#e6e6e6;">
                        <th><input id="all_id" type="checkbox"></th>
                        <th>设备名称</th>
                        <th>设备SN</th>
                        <th>租借人</th>
                        <th>身份证号</th>
                        <th>联系方式</th>
                        <th>租借日期</th>
                        <th>已付押金</th>
                        <th>归还日期</th>
                        <th>归还设备状态</th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
        <div class="loading" style="display: none;">
            <img src="${newframe }/images/slidebar/loading.gif" class="loadingImg">
        </div>
    </div>
    <!--startprint-->
    <div style="width:600px;margin:0 auto;display:none;font-size:17px;" id="putContent">
        <p style="text-align:center;margin-bottom:20px;font-size:25px"><span class="hospitalName"></span>居民家用远程设备服务协议
        </p>
        <p>甲方：<span class="hospitalName"></span></p>
        <p>
            乙方：
            <span class="rentMan"></span>
            <span style="margin-left:30%;" class="idcard">身份证号码：</span>
            <span class="Card"></span>
        </p>
        <ul style="margin:30px 0;">
            <li>1.甲方为了提高慢性病管理质量，从第三方引进远程监测设备，设备的销售和维护及售后由第三方负责，与甲方无关。</li>
            <li>2.乙方必须参加家庭医生签约服务，本项目为家庭医生签约的增值服务包的内容。</li>
            <li>3.甲方无偿为乙方提供远程管理的服务，双方不构成医疗服务的责任关系，不承担疾病所带来的风险责任和法律责任。</li>
            <li>4.乙方自愿接受并配合甲方的远程指导和电话随访。</li>
            <li>5.本协议一式两份，最终解释权归甲方所有。</li>
        </ul>
        <div style="float:right;">
            <p>甲方：</p>
            <p>乙方：</p>
            <p>
                协议签订日期：______年______月______日
            </p>
        </div>
    </div>
    <!--endprint-->
</div>
<script>
    function rent() {
        window.parent.showNewModelIframe("${URL_RENT_TORENT}", 850, 500);
    }

    function back() {
        var checkedArray = getCheckedArray();
        if (checkedArray.length != 1) {
            alert("请勾选一条数据修改");
            return;
        }
        window.parent.showNewModelIframe("${URL_RENT_TOBACK}?id=" + checkedArray[0], 850, 500);
    }

    function put() {
        var checkedArray = getCheckedArray();
        if (checkedArray.length != 1) {
            alert("请勾选一条数据修改");
            return;
        }
        if (navigator.userAgent.toLowerCase().indexOf("chrome") == -1) {
            alert('请使用谷歌浏览器，否则相关功能将不能正常使用！')
        }
        GetData(checkedArray[0]);
        $('#putContent').css({
            'display': 'block'
        });
        remove_ie_header_and_footer();
//        $('#putContent').css({
//            'width':'80%'
//        })
        $('.idcard').css({
            'marginLeft': '10%'
        });
        var bdhtml = window.document.body.innerHTML
        // 设置打印开始区域
        var startStr = '<!--startprint-->'
        // 设置打印结束区域
        var endStr = '<!--endprint-->'
        // 从标记里获取需要打印的页面
        var printHtml = bdhtml.substring(bdhtml.indexOf(startStr) + startStr.length, bdhtml.indexOf(endStr))
        // 也可以通过id获取
        // var printHtml = document.getElementById('printid').innerHTML
        // 需要打印的页面
        window.document.body.innerHTML = printHtml
        window.print()
        // 还原界面
        window.document.body.innerHTML = bdhtml
        $('#putContent').css({
            'display': 'none'
        })
        parent.showSrc(window.location.href)
    }

    function remove_ie_header_and_footer() {
        var hkey_path;
        $('h3').css({
            'fontSize': '30px'
        })
        try {
            var RegWsh = new ActiveXObject("WScript.Shell")
            hkey_key = "header"
            RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "&w&b页码，&p/&P")
            hkey_key = "footer"
            RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "&u&b&d")
        } catch (e) {
        }
    }

    function updateHistory() {
        var checkedArray = getCheckedArray();
        if (checkedArray.length != 1) {
            alert("请勾选一条数据修改");
            return;
        }
        window.parent.showNewModelIframe("${URL_RENT_TORENTHISTORY}?id=" + checkedArray[0], 850, 500);
    }

    var table;

    function initTable() {
        table = $('#example')
            .DataTable(
                {
                    "dom": "<'row'<'#mytool.col-xs-10'><'col-xs-6'f>r>"
                        + "t"
                        + "<'row pageNum'<p>>",
                    "bFilter": false,//去掉搜索框
                    "sLengthMenu": [10],
                    "bAutoWidth": true, //自适应宽度
                    "bInfo": false,
                    "sPaginationType": "full_numbers",
                    "ordering": false,//是否允许Datatables开启排序
                    "bProcessing": true,
                    "bServerSide": true,
                    "sScrollX": "100%",
                    "sAjaxSource": "${URL_RENT_SEARCHRENT}",
                    "sAjaxDataProp": "dataList",//查询后，返回的集合
                    "fnServerData": function (sSource, aoData,
                                              fnCallback) { //查询条件
                        aoData.push(
                            {"name": "instrumentType", "value": $("#instrumentType").val()},
                            {"name": "instrumentSN", "value": $("#instrumentSN").val()},
                            {"name": "rentMan", "value": $("#rentMan").val()},
                            {"name": "idCard", "value": $("#idCard").val()},
                            {"name": "rentStatus", "value": $("#rentStatus").val()}
                        );
                        $.ajax({
                            "dataType": 'json',
                            "url": sSource,
                            "type": 'post',
                            "data": aoData,
                            "success": function (resp) {
                                var page = parseInt(resp.iTotalRecords / 10) + 3;
                                if (page >= 9) {
                                    page = 9;
                                }
                                var W = page * 45;
                                $('.pageNum').width(W + 'px');
                                fnCallback(resp);
                            }
                        });

                    },

                    "aoColumns": [
                        {
                            "targets": 0,
                            "data": null,
                            "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                                $(nTd).html('' + '&nbsp;&nbsp;<input name="id" id = "' + oData.rentId + '" value="' + oData.rentId + '" type="checkbox"><label for=' + oData.rentId + '></label>' + '');
                            }
                        },
                        {
                            "mDataProp": "instrumentType"
                        },
                        {
                            "mDataProp": "instrumentSN"
                        },
                        {
                            "targets": 0,
                            "data": null,
                            "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                                $(nTd).html('' +
                                    '&nbsp;&nbsp;<a href="##" onClick="Then(this)" style="color:black;border-bottom:#35acfd dashed 1px">' + oData.rentMan +
                                    '<span style="display:none">' + oData.idCard + '</span>' + '</a>' +
                                    '')
                            }
                        },

                        {
                            "mDataProp": "idCard"
                        },
                        {
                            "mDataProp": "rentTel"
                        },
                        {
                            "mDataProp": "rentTime"
                        },
                        {
                            "mDataProp": "rentMoney"
                        },
                        {
                            "mDataProp": "backTime"
                        },
                        {
                            "targets": 8,
                            "data": null,
                            "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                                var configs = <medi:configJson name="backStatus"/>;
                                $(nTd).html(!configs[sData.backStatus] ? "" : configs[sData.backStatus]);
                            }
                        }],
                    "oLanguage": {//插件的汉化
                        "sLengthMenu": '',
                        "sZeroRecords": "抱歉， 没有找到",
                        "sInfoEmpty": "没有数据",
                        "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                        "oPaginate": {
                            "sFirst": "",
                            "sPrevious": "<b>上一页<b>",
                            "sLast": "",
                            "sNext": "<i>下一页</i>"

                        },
                        "sZeroRecords": "没有检索到数据",
                        "sProcessing": "<img src='' />",
                        "sSearch": "搜索"
                    },
                    "initComplete": function () {
                        <shiro:hasPermission name="instrument:add">
                        $("#mytool").append(
                            '<button id="update_butt" type="button" onclick="put()" style="float:right">打印</button>');
                        </shiro:hasPermission>
                        <shiro:hasPermission name="instrument:add">
                        $("#mytool").append(
                            '<button id="update_butt" type="button" onclick="updateHistory()" style="float:right">修改</button>');
                        </shiro:hasPermission>
                        <shiro:hasPermission name="instrument:update">
                        $("#mytool").append('<button id="back_butt" type="button" onclick="back()" style="float:right" >归还</button>');
                        </shiro:hasPermission>
                        <shiro:hasPermission name="instrument:delete">
                        $("#mytool").append('<button id="rent_butt" type="button" onclick="rent()" style="float:right" >租借</button>');
                        </shiro:hasPermission>
                    }
                });
    }

    function getCheckedArray() {
        var checkedArray = [];
        $("input[name='id']").each(function () {
            if (this.checked) {
                checkedArray.push(this.value);
            }
        });
        return checkedArray;
    }

    function Then(obj) {
        var idCard = obj.childNodes[1].innerText
        // 查询病人信息
        var url = '${URL_PATIENT_TOARCHIVES}?idCard=' + idCard + '&diseasesType=' + '' + '&type=' + Type
        var Type
        $.ajax({
            url: "${URL_SCREENING_GETBREADLINE}",
            dataType: 'json',
            type: 'post',
            success: function (data) {
                breadLine = JSON.parse(data.data)
                breadLine.push({
                    name: '病人信息',
                    href: url
                })
                $.ajax({
                    url: '${URL_SCREENING_SAVEBREADLINE}',
                    data: {
                        breadLine: JSON.stringify(breadLine)
                    },
                    dataType: 'json',
                    type: 'post',
                    success: function (data) {
                        parent.showSrc('${URL_PATIENT_TOARCHIVES}?idCard=' + idCard + '&diseasesType=' + '' + '&type=' + Type)
                    }
                })
            }
        })
    }

    window.onload = function () {
        initTable();
        if (location.search != '') {
            console.log(location.search.split('?')[1].split('=')[1])
            if (navigator.userAgent.toLowerCase().indexOf("chrome") == -1) {
                alert('请使用谷歌浏览器，否则相关功能将不能正常使用！')
            }
            GetData(location.search.split('?')[1].split('=')[1])
            $('#putContent').css({
                'display': 'block'
            })
            remove_ie_header_and_footer()
            $('.idcard').css({
                'marginLeft': '10%'
            })
            $('.otherContent').css({
                'display': 'none'
            })
            var bdhtml = window.document.body.innerHTML
            // 设置打印开始区域
            var startStr = '<!--startprint-->'
            // 设置打印结束区域
            var endStr = '<!--endprint-->'
            // 从标记里获取需要打印的页面
            var printHtml = bdhtml.substring(bdhtml.indexOf(startStr) + startStr.length, bdhtml.indexOf(endStr))
            // 也可以通过id获取
            // var printHtml = document.getElementById('printid').innerHTML
            // 需要打印的页面
            window.document.body.innerHTML = printHtml
            window.print()
            // 还原界面
            parent.showSrc('${URL_RENT_TORENTMGR}')
        }
    };
</script>
</body>
</html>
